#!/bin/bash

# Stop All Providers Script
# Author: BCXJ
# Version: 1.0

echo "================================================="
echo "Stopping All Dubbo Providers..."
echo "================================================="

PROJECT_DIR="$(dirname "$0")/demo-dubbo-service"

# Stop Annotation Provider
if [ -f "$PROJECT_DIR/annotation-provider.pid" ]; then
    ANNOTATION_PID=$(cat "$PROJECT_DIR/annotation-provider.pid")
    echo "Stopping Annotation Provider (PID: $ANNOTATION_PID)..."
    kill $ANNOTATION_PID 2>/dev/null
    if [ $? -eq 0 ]; then
        echo "Annotation Provider stopped successfully"
        rm "$PROJECT_DIR/annotation-provider.pid"
    else
        echo "Annotation Provider is not running or already stopped"
        rm "$PROJECT_DIR/annotation-provider.pid" 2>/dev/null
    fi
else
    echo "Annotation Provider PID file not found"
fi

echo ""

# Stop XML Provider
if [ -f "$PROJECT_DIR/xml-provider.pid" ]; then
    XML_PID=$(cat "$PROJECT_DIR/xml-provider.pid")
    echo "Stopping XML Provider (PID: $XML_PID)..."
    kill $XML_PID 2>/dev/null
    if [ $? -eq 0 ]; then
        echo "XML Provider stopped successfully"
        rm "$PROJECT_DIR/xml-provider.pid"
    else
        echo "XML Provider is not running or already stopped"
        rm "$PROJECT_DIR/xml-provider.pid" 2>/dev/null
    fi
else
    echo "XML Provider PID file not found"
fi

echo ""
echo "================================================="
echo "All providers stopped"
echo "================================================="

